<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UsersControl.ascx.cs" Inherits="xManagerWebApp.__AdminPage.UsersControl" %>


<asp:LinqDataSource ID="source" runat="server" OnSelecting="OnLinqDataSourceSelecting">
</asp:LinqDataSource>

<asp:Label ID="lblErrorMessage" runat="server" ForeColor="Red" />

<asp:Panel ID="listPanel" runat="server">
    
    <br />
    <br />
    <table>
        <tr>
            <td><asp:Label runat="server" ID="lblSearchName" Text="Name:" /></td>
            <td><asp:TextBox ID="editSearchName" runat="server" /></td>
            <td><asp:Label runat="server" ID="lblSearchUserName" Text="Login:" /></td>
            <td><asp:TextBox ID="editSearchUserName" runat="server" /></td>
        </tr>
        <tr>
            <td colspan="2"> 
                <br />
                <asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="OnSearch" style="margin:5px" />
                <asp:Button ID="btnNew" runat="server" OnClick="OnNew" Text="New" style="margin:5px" />
            </td>
        </tr>
    </table>
    <br />
    <asp:GridView ID="grid" runat="server" HeaderStyle-ForeColor="White" AutoGenerateColumns="False" EmptyDataText="No users to list." 
        DataKeyNames="Id" DataSourceID="source" OnSelectedIndexChanged="OnSelected" AllowPaging="True" AllowSorting="True" style="width:500px" >
        <Columns>
            <asp:TemplateField >
                <ItemTemplate>
                    <asp:ImageButton ID="btnSelect" runat="server" CommandName="Select" ImageUrl="~/Images/goto.png" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="Shortname" HeaderText="Name" SortExpression="Shortname" />  
            <asp:BoundField DataField="UserName" HeaderText="Login" SortExpression="UserName" />  
            <asp:BoundField DataField="Email" HeaderText="E-mail" SortExpression="Email" />  
        </Columns>
    </asp:GridView>
    
</asp:Panel>

<asp:Panel ID="editPanel" runat="server" Visible="false">
    <asp:label ID="Label1" text="Edit User" runat="server" SkinID="LabelMainTitle" />
    <br />
        <asp:ValidationSummary ID="ValidationSummary1" runat="server" ForeColor="Red" DisplayMode="BulletList" />
    <br />
    <asp:Button ID="btnSave" runat="server" Text="Save" OnClick="OnSave" style="margin:5px" />
    <asp:Button ID="btnDelete" runat="server" Text="Delete" OnClick="OnDelete" OnClientClick="return confirm('Are your sure that you want to delete this user?')" style="margin:5px"/>
    <asp:Button ID="btnReturn" runat="server" Text="Back" OnClick="OnReturn" CausesValidation="false" style="margin:5px"/>
    <br />
    <table>
        <tr>
            <td >
                <asp:Label ID="lblName" Text="Name" runat="server" />
            </td>
            <td>&nbsp;</td>
            <td >
                <asp:TextBox runat="server" ID="editName" />
                <asp:RequiredFieldValidator runat="server" ID="reqEditName" ControlToValidate="editName"
                    ErrorMessage="'Name' field is mandatory">*</asp:RequiredFieldValidator>
            </td>
        </tr>        
        <tr>
            <td >
                <asp:Label ID="lblLogin" Text="Login" runat="server" />
            </td>
            <td>&nbsp;</td>
            <td >
                <asp:TextBox runat="server" ID="editLogin" />
                <asp:RequiredFieldValidator runat="server" ID="reqEditLogin" ControlToValidate="editLogin"
                    ErrorMessage="'Login' field is mandatory">*</asp:RequiredFieldValidator>
            </td>
         </tr>
         <tr>
            <td >
                <asp:Label ID="lblPassword" Text="Password"  runat="server" />
            </td>
            <td>&nbsp;</td>
            <td >
                <asp:TextBox runat="server" TextMode="Password" id="editPassword"></asp:TextBox>
            </td>
         </tr>
         <tr>
            <td >
                <asp:Label ID="lblConfPassword" Text="Password Confirmation" runat="server" />
            </td>
            <td>&nbsp;</td>
            <td >
                <asp:TextBox runat="server" TextMode="PassWord" id="editConfPassword"></asp:TextBox>
                <asp:CompareValidator ID="comparePasswordValidator" ControlToValidate="editConfPassword"  
                    ControlToCompare="editPassword" runat="server" Operator="Equal" 
                    ErrorMessage="Password don't match" Type="String">*</asp:CompareValidator>
            </td>
        </tr>
        <tr>
            <td >
                <asp:Label ID="lblEmail" Text="E-Mail" runat="server" />
            </td>
            <td>&nbsp;</td>
            <td >
                <asp:TextBox runat="server" id="editEmail"></asp:TextBox>
                <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
                    ErrorMessage="Invalid E-mail" ControlToValidate="editEmail" 
                    ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">*</asp:RegularExpressionValidator>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                    ErrorMessage="E-mail is mandatory" ControlToValidate="editEmail">*</asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td valign="top">
                <asp:Label ID="lblRole" Text="Role"  runat="server" />
            </td>
            <td>&nbsp;</td>
            <td>
                <asp:RadioButtonList ID="editRole" runat="server" DataTextField="RoleName" DataValueField="RoleId">
                </asp:RadioButtonList>
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="editRole" 
                    ErrorMessage="Role is mandatory">*</asp:RequiredFieldValidator>
            </td>
        </tr>
    </table>
</asp:Panel>
